#ifndef QQTDATACACHE_H
#define QQTDATACACHE_H

#include <QObject>

#include <qqtdictionary.h>
#include <qqtdatamanager.h>
#include <qqtfindservermanager.h>

#include <qqthighgrade_global.h>

/**
 * @brief The QQtCalculateProtocol class
 * 数学统计协议。
 *
 * [0] "cal"
 * [1] -xxx -> +xxx
 *
 * [0] "cal_ack"
 * [1] 200
 */
class QQTHIGHGRADESHARED_EXPORT QQtCalculateProtocol : public QQtDataProtocol
{
    Q_OBJECT
public:
    explicit QQtCalculateProtocol ( QObject* parent = 0 );
    virtual ~QQtCalculateProtocol();

    int sendValue ( int value );

private:

    // QQtDataProtocol interface
public:
    virtual void recvMessage ( const QQtDataSerialization& data ) override;
};

/**
 * @brief The QQtCalculateManager class
 */
class QQTHIGHGRADESHARED_EXPORT QQtCalculateManager: public QObject
{
    Q_OBJECT

public:
    explicit QQtCalculateManager ( QObject* parent = 0 );
    virtual ~QQtCalculateManager();

    void setServerAddress ( QHostAddress address, int port = 4417 );
    void setListeningAddress ( QHostAddress address, int port = 4418 );
    void setListeningPort ( int port = 4418 );

    void sendValue ( int value );

signals:

protected:

protected slots:

protected:

private:

    QQtUdpClient* c0;
    QQtCalculateProtocol* p0;
};

/**
 * @brief The QQtCalculateServerProtocol class
 */
class QQTHIGHGRADESHARED_EXPORT QQtCalculateServerProtocol : public QQtDataProtocol
{
    Q_OBJECT
public:
    explicit QQtCalculateServerProtocol ( QObject* parent = 0 );
    virtual ~QQtCalculateServerProtocol();

    int recvValue ( int value );
    void sendCalAck();

signals:
    void signalRecvValue ( int value );
private:

    // QQtDataProtocol interface
public:
    virtual void recvMessage ( const QQtDataSerialization& data ) override;
};

/**
 * @brief The QQtCalculateServerProtocolManager class
 */
class QQTHIGHGRADESHARED_EXPORT QQtCalculateServerProtocolManager : public QQtProtocolManager
{
    Q_OBJECT
public:
    explicit QQtCalculateServerProtocolManager ( QObject* parent = 0 );
    virtual ~QQtCalculateServerProtocolManager();

signals:
    void signalRecvValue ( int value );

private:

    // QQtProtocolManager interface
public:
    virtual QQtProtocol* createProtocol() override;
};

class QQTHIGHGRADESHARED_EXPORT QQtCalculateServerManager: public QObject
{
    Q_OBJECT

public:
    explicit QQtCalculateServerManager ( QObject* parent = 0 );
    virtual ~QQtCalculateServerManager();

    void setListeningAddress ( QHostAddress address, int port = 4417 );
    void setListeningPort ( int port = 4417 );

signals:
    void signalRecvValue ( int value );

protected:

protected slots:
    void remainingProtocolChanged ( int );

protected:

private:

    QQtUdpServer* s0;
    QQtCalculateServerProtocolManager* m0;
};

typedef QQtCalculateServerManager QQtDataCache;
typedef QQtCalculateManager QQtDataCacheManager;

#endif // QQTDATACACHE_H

